home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / plot.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-02  |  14.5 KB  |  587 lines

  1. /*
  2.  * $Id: plot.h%v 3.38.2.81 1993/02/24 02:29:34 woo Exp woo $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - plot.h */
  7. /*
  8.  * Copyright (C) 1986 - 1993   Thomas Williams, Colin Kelley
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software is provided "as is" without express or implied warranty.
  21.  * 
  22.  *
  23.  * AUTHORS
  24.  * 
  25.  *   Original Software:
  26.  *     Thomas Williams,  Colin Kelley.
  27.  * 
  28.  *   Gnuplot 2.0 additions:
  29.  *       Russell Lang, Dave Kotz, John Campbell.
  30.  *
  31.  *   Gnuplot 3.0 additions:
  32.  *       Gershon Elber and many others.
  33.  * 
  34.  * Send your comments or suggestions to 
  35.  *  info-gnuplot@dartmouth.edu.
  36.  * This is a mailing list; to join it send a note to 
  37.  *  info-gnuplot-request@dartmouth.edu.  
  38.  * Send bug reports to
  39.  *  bug-gnuplot@dartmouth.edu.
  40.  */
  41.  
  42. #define PROGRAM "G N U P L O T"
  43. #define PROMPT "gnuplot> "
  44. #if defined(AMIGA_SC_6_1) || defined(AMIGA_AC_5)
  45. #define SHELL "NewShell"
  46. #else /* AMIGA */
  47. #ifdef ATARI
  48. #define SHELL "gulam.prg"
  49. #else /* ATARI */
  50. #ifdef OS2
  51. #define SHELL "c:\\cmd.exe"
  52. #else /*OS2 */
  53. #define SHELL "/bin/sh"        /* used if SHELL env variable not set */
  54. #endif /*OS2 */
  55. #endif /* ATARI */
  56. #endif /* AMIGA  */
  57.  
  58. #if defined(__unix__) && !defined(unix)
  59. #define unix
  60. #endif
  61.  
  62. #define SAMPLES 100        /* default number of samples for a plot */
  63. #define ISO_SAMPLES 10        /* default number of isolines per splot */
  64. #define ZERO    1e-8        /* default for 'zero' set option */
  65.  
  66. #ifndef TERM
  67. /* default terminal is "unknown"; but see init_terminal */
  68. #define TERM "unknown"
  69. #endif
  70.  
  71. #define TRUE 1
  72. #define FALSE 0
  73.  
  74.  
  75. #define Pi 3.141592653589793
  76. #define DEG2RAD (Pi / 180.0)
  77.  
  78.  
  79. #define MIN_CRV_POINTS 100        /* minimum size of points[] in curve_points */
  80. #define MIN_SRF_POINTS 1000        /* minimum size of points[] in surface_points */
  81.  
  82. #define MAX_LINE_LEN 1024    /* maximum number of chars allowed on line */
  83. #define MAX_TOKENS 400
  84. #define MAX_ID_LEN 50        /* max length of an identifier */
  85.  
  86.  
  87. #define MAX_AT_LEN 150        /* max number of entries in action table */
  88. #define STACK_DEPTH 100
  89. #define NO_CARET (-1)
  90.  
  91.  
  92. #define MAX_NUM_VAR    5    /* Ploting projection of func. of max. five vars. */
  93.  
  94. #define MAP3D_CARTESIAN        0    /* 3D Data mapping. */
  95. #define MAP3D_SPHERICAL        1
  96. #define MAP3D_CYLINDRICAL    2
  97.  
  98. #define CONTOUR_NONE    0    /* Where to place contour maps if at all. */
  99. #define CONTOUR_BASE    1
  100. #define CONTOUR_SRF    2
  101. #define CONTOUR_BOTH    3
  102.  
  103. #define CONTOUR_KIND_LINEAR    0 /* See contour.h in contours subdirectory. */
  104. #define CONTOUR_KIND_CUBIC_SPL    1
  105. #define CONTOUR_KIND_BSPLINE    2
  106.  
  107. #define LEVELS_AUTO            0        /* How contour levels are set */
  108. #define LEVELS_INCREMENTAL    1        /* user specified start & incremnet */
  109. #define LEVELS_DISCRETE        2        /* user specified discrete levels */
  110. #define MAX_DISCRETE_LEVELS   30
  111.  
  112. #define ANGLES_RADIANS    0
  113. #define ANGLES_DEGREES    1
  114.  
  115.  
  116. #if defined(AMIGA_SC_6_1) || defined(AMIGA_AC_5)
  117. #define OS "Amiga "
  118. #endif
  119.  
  120. #ifdef OS2
  121. #ifdef unix
  122. #undef unix    /* GCC might declare this */
  123. #define OS "OS/2"
  124. #endif
  125. #endif  /* OS2 */
  126.  
  127. #ifdef vms
  128. #define OS "VMS "
  129. #endif
  130.  
  131.  
  132. #ifdef unix
  133. #define OS "unix "
  134. #endif
  135.  
  136.  
  137. #ifdef _WINDOWS
  138. #define _Windows
  139. #endif
  140.  
  141. #ifdef DOS386
  142. #define OS "DOS 386 "
  143. #endif
  144. #ifdef _Windows
  145. #define OS "MS-Windows "
  146. #else
  147. #ifdef MSDOS
  148. #ifdef unix    /* __EMX__ and DJGPP may set this */
  149. #undef OS
  150. #undef unix
  151. #endif
  152. #define OS "MS-DOS "
  153. #endif
  154. #endif
  155.  
  156.  
  157. #ifdef ATARI
  158. #define OS "TOS "
  159. #endif
  160.  
  161. #ifndef OS
  162. #define OS ""
  163. #endif
  164.  
  165.  
  166. /* To access curves larger than 64k, MSDOS needs to use huge pointers */
  167. #if (defined(__TURBOC__) && defined(MSDOS)) || (defined(_Windows) && !defined(WIN32))
  168. #define GPHUGE huge
  169. #define GPFAR far
  170. #else
  171. #define GPHUGE
  172. #define GPFAR
  173. #endif
  174.  
  175.  
  176. /*
  177.  * Note about VERYLARGE:  This is the upper bound double (or float, if PC)
  178.  * numbers. This flag indicates very large numbers. It doesn't have to 
  179.  * be the absolutely biggest number on the machine.  
  180.  * If your machine doesn't have HUGE, or float.h,
  181.  * define VERYLARGE here. 
  182.  *
  183.  * This is a mess.  If someone figures out how to clean this up, please
  184.  *    diff -c  of your fixes
  185.  *
  186.  *
  187.  * example:
  188. #define VERYLARGE 1e37
  189.  */
  190.  
  191. #ifdef ATARI
  192. #include <stdlib.h>        /* Prototyping used !! 'size_t' */
  193. #include <stdio.h>
  194. #include <string.h>
  195. #include <math.h>
  196. #define VERYLARGE    HUGE_VAL
  197. #else  /* not ATARI */
  198. #if defined(MSDOS) || defined(_Windows)
  199. #include <float.h>
  200. #define VERYLARGE (FLT_MAX/2 -1)
  201. #else  /* not MSDOS || _Windows */
  202. #if defined( vms ) || defined( _CRAY ) || defined( NEXT ) || defined(__osf__) || defined( OS2 ) || defined(__EMX__) || defined( DOS386)
  203. #include <float.h>
  204. #if defined ( NEXT )  /* bug in NeXT OS 2.0 */
  205. #if defined ( DBL_MAX)
  206. #undef DBL_MAX
  207. #endif
  208. #define DBL_MAX 1.7976931348623157e+308 
  209. #undef HUGE
  210. #define HUGE    DBL_MAX
  211. #undef HUGE_VAL
  212. #define HUGE_VAL DBL_MAX
  213. #endif /* not NEXT but CRAY, VMS or OSF */
  214. #define VERYLARGE (DBL_MAX/2 -1)
  215. #else  /* not vms, CRAY, NEXT, OS/2 or OSF */
  216. #ifdef AMIGA_AC_5
  217. #include <math.h>
  218. #define VERYLARGE (HUGE/2 -1)
  219. #else /* not AMIGA_AC_5 */
  220. #ifdef AMIGA_SC_6_1
  221. #include <float.h>
  222. #ifndef HUGE
  223. #define HUGE DBL_MAX
  224. #endif
  225. #define VERYLARGE (HUGE/2 -1)
  226. #else /* !AMIGA_SC_6_1 */
  227. /* #include <float.h> */
  228. #ifdef ISC22
  229. #include <float.h>
  230. #ifndef HUGE
  231. #define HUGE DBL_MAX
  232. #endif
  233. #endif /* ISC22 */
  234. /* This is the default */
  235. #ifndef HUGE
  236. #define HUGE DBL_MAX
  237. #endif
  238. #define VERYLARGE (HUGE/2 -1)
  239. /* default */
  240. #endif /* !AMIGA_SC_6_1 */
  241. #endif /* !AMIGA_AC_5 */
  242. #endif /* !VMS !CRAY !NEXT */
  243. #endif /* !MSDOS || !_Windows */
  244. #endif /* !ATARI */
  245.  
  246. #ifdef AMIGA_SC_6_1
  247. /* Get function prototypes */
  248. #include <stdio.h>
  249. #include <stdlib.h>
  250. #include <string.h>
  251. #include <math.h>
  252. #endif /* AMIGA_SC_6_1 */
  253.  
  254. #define END_OF_COMMAND (c_token >= num_tokens || equals(c_token,";"))
  255.  
  256. #ifdef vms
  257.  
  258.  
  259. #define is_comment(c) ((c) == '#' || (c) == '!')
  260. #define is_system(c) ((c) == '$')
  261.  
  262.  
  263. #else /* vms */
  264.  
  265. #define is_comment(c) ((c) == '#')
  266. #define is_system(c) ((c) == '!')
  267.  
  268. #endif /* vms */
  269.  
  270. /* If you don't have vfork, then undefine this */
  271. #if defined(NOVFORK) || defined(MSDOS) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  272. # undef VFORK
  273. #else
  274. # ifdef unix
  275. #  define VFORK
  276. # endif
  277. #endif
  278.  
  279. /* 
  280.  * memcpy() comes by many names. The default is now to assume bcopy, 
  281.  * since it is the most common case. Define 
  282.  *  MEMCPY to use memcpy(), 
  283.  *  vms to use the vms function,
  284.  *  NOCOPY to use a handwritten version in parse.c
  285.  */
  286. #ifdef vms
  287. # define memcpy(dest,src,len) lib$movc3(&len,src,dest)
  288. #else
  289. # if defined(MEMCPY) || defined(MSDOS) || defined (ATARI) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  290.    /* use memcpy directly */
  291. # else 
  292. #  ifdef NOCOPY
  293.     /* use the handwritten memcpy in parse.c */
  294. #  else
  295.     /* assume bcopy is in use */
  296. #   define memcpy(dest,src,len) bcopy(src,dest,len)
  297. #  endif /* NOCOPY */
  298. # endif /* MEMCPY || MSDOS */
  299. #endif /* vms */
  300.  
  301. /*
  302.  * In case you have MEMSET instead of BZERO. If you have something 
  303.  * else, define bzero to that something.
  304.  */
  305. #if defined(MEMSET) || defined(MSDOS) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  306. #define bzero(dest,len)  (void)(memset(dest, 0, len))
  307. #endif /* MEMSET || MSDOS */
  308.  
  309. #define top_of_stack stack[s_p]
  310.  
  311. typedef int TBOOLEAN;
  312.  
  313. #ifdef __ZTC__
  314. typedef int (*FUNC_PTR)(...);
  315. #else
  316. typedef int (*FUNC_PTR)();
  317. #endif
  318.  
  319. enum operators {
  320.     PUSH, PUSHC, PUSHD1, PUSHD2, PUSHD, CALL, CALLN, LNOT, BNOT, UMINUS,
  321.     LOR, LAND, BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT,
  322.     DIV, MOD, POWER, FACTORIAL, BOOLE, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  323. };
  324.  
  325.  
  326. #define is_jump(operator) ((operator) >=(int)JUMP && (operator) <(int)SF_START)
  327.  
  328.  
  329. enum DATA_TYPES {
  330.     INTGR, CMPLX
  331. };
  332.  
  333.  
  334. enum PLOT_TYPE {
  335.     FUNC, DATA, FUNC3D, DATA3D
  336. };
  337.  
  338. /*XXX - JG */
  339. enum PLOT_STYLE {
  340.     LINES, POINTSTYLE, IMPULSES, LINESPOINTS, DOTS, ERRORBARS, BOXES, BOXERROR, STEPS
  341. };
  342.  
  343. enum JUSTIFY {
  344.     LEFT, CENTRE, RIGHT
  345. };
  346.  
  347. #if !(defined(ATARI)&&defined(__GNUC__)&&defined(_MATH_H)) /* FF's math.h has the type already */
  348. struct cmplx {
  349.     double real, imag;
  350. };
  351. #endif
  352.  
  353.  
  354. struct value {
  355.     enum DATA_TYPES type;
  356.     union {
  357.         int int_val;
  358.         struct cmplx cmplx_val;
  359.     } v;
  360. };
  361.  
  362.  
  363. struct lexical_unit {    /* produced by scanner */
  364.     TBOOLEAN is_token;    /* true if token, false if a value */ 
  365.     struct value l_val;
  366.     int start_index;    /* index of first char in token */
  367.     int length;            /* length of token in chars */
  368. };
  369.  
  370.  
  371. struct ft_entry {        /* standard/internal function table entry */
  372.     char *f_name;        /* pointer to name of this function */
  373.     FUNC_PTR func;        /* address of function to call */
  374. };
  375.  
  376.  
  377. struct udft_entry {                /* user-defined function table entry */
  378.     struct udft_entry *next_udf;         /* pointer to next udf in linked list */
  379.     char udf_name[MAX_ID_LEN+1];         /* name of this function entry */
  380.     struct at_type *at;            /* pointer to action table to execute */
  381.     char *definition;             /* definition of function as typed */
  382.     struct value dummy_values[MAX_NUM_VAR];    /* current value of dummy variables */
  383. };
  384.  
  385.  
  386. struct udvt_entry {            /* user-defined value table entry */
  387.     struct udvt_entry *next_udv; /* pointer to next value in linked list */
  388.     char udv_name[MAX_ID_LEN+1]; /* name of this value entry */
  389.     TBOOLEAN udv_undef;        /* true if not defined yet */
  390.     struct value udv_value;    /* value it has */
  391. };
  392.  
  393.  
  394. union argument {            /* p-code argument */
  395.     int j_arg;                /* offset for jump */
  396.     struct value v_arg;        /* constant value */
  397.     struct udvt_entry *udv_arg;    /* pointer to dummy variable */
  398.     struct udft_entry *udf_arg; /* pointer to udf to execute */
  399. };
  400.  
  401.  
  402. struct at_entry {            /* action table entry */
  403.     enum operators index;    /* index of p-code function */
  404.     union argument arg;
  405. };
  406.  
  407.  
  408. struct at_type {
  409.     int a_count;                /* count of entries in .actions[] */
  410.     struct at_entry actions[MAX_AT_LEN];
  411.         /* will usually be less than MAX_AT_LEN is malloc()'d copy */
  412. };
  413.  
  414.  
  415. /* Defines the type of a coordinate */
  416. /* INRANGE and OUTRANGE points have an x,y point associated with them */
  417. enum coord_type {
  418.     INRANGE,                /* inside plot boundary */
  419.     OUTRANGE,                /* outside plot boundary, but defined */
  420.     UNDEFINED                /* not defined at all */
  421. };
  422.   
  423. #if defined(MSDOS) || defined(_Windows) 
  424. typedef float coordval;        /* memory is tight on PCs! */
  425. #else
  426. typedef double coordval;
  427. #endif
  428.  
  429. struct coordinate {
  430.     enum coord_type type;    /* see above */
  431.     coordval x, y, z;
  432.     coordval ylow, yhigh;    /* ignored in 3d */
  433. #if (defined(_Windows) && !defined(WIN32)) || (defined(MSDOS) && defined(__TURBOC__))
  434.     char pad[10];        /* pad to 32 byte boundary */
  435. #endif
  436. };
  437.  
  438. struct curve_points {
  439.     struct curve_points *next_cp;    /* pointer to next plot in linked list */
  440.     enum PLOT_TYPE plot_type;
  441.     enum PLOT_STYLE plot_style;
  442.     char *title;
  443.     int line_type;
  444.     int point_type;
  445.      int p_max;                    /* how many points are allocated */
  446.     int p_count;                    /* count of points in points */
  447.     struct coordinate GPHUGE *points;
  448. };
  449.  
  450. struct gnuplot_contours {
  451.     struct gnuplot_contours *next;
  452.     struct coordinate GPHUGE *coords;
  453.      char isNewLevel;
  454.      char label[12];
  455.     int num_pts;
  456. };
  457.  
  458. struct iso_curve {
  459.     struct iso_curve *next;
  460.      int p_max;                    /* how many points are allocated */
  461.     int p_count;                    /* count of points in points */
  462.     struct coordinate GPHUGE *points;
  463. };
  464.  
  465. struct surface_points {
  466.     struct surface_points *next_sp;    /* pointer to next plot in linked list */
  467.     enum PLOT_TYPE plot_type;
  468.     enum PLOT_STYLE plot_style;
  469.     char *title;
  470.     int line_type;
  471.     int point_type;
  472.     int has_grid_topology;
  473.     int num_iso_read;  /* Data files only - num of isolines read from file. */
  474.     struct gnuplot_contours *contours;    /* Not NULL If have contours. */
  475.     struct iso_curve *iso_crvs;
  476. };
  477.  
  478. struct TERMENTRY {
  479.     char *name;
  480.     char *description;
  481.     unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
  482.     FUNC_PTR options,init,reset,text,scale,graphics,move,vector,linetype,
  483.         put_text,text_angle,justify_text,point,arrow;
  484. };
  485.  
  486. #ifdef _Windows
  487. #define termentry TERMENTRY far
  488. #else
  489. #define termentry TERMENTRY
  490. #endif
  491.  
  492.  
  493. struct text_label {
  494.     struct text_label *next;    /* pointer to next label in linked list */
  495.     int tag;            /* identifies the label */
  496.     double x,y,z;
  497.     enum JUSTIFY pos;
  498.     char text[MAX_LINE_LEN+1];
  499. };
  500.  
  501. struct arrow_def {
  502.     struct arrow_def *next;    /* pointer to next arrow in linked list */
  503.     int tag;            /* identifies the arrow */
  504.     double sx,sy,sz;        /* start position */
  505.     double ex,ey,ez;        /* end position */
  506.     TBOOLEAN head;            /* arrow has a head or not */
  507. };
  508.  
  509. /* Tic-mark labelling definition; see set xtics */
  510. struct ticdef {
  511.     int type;                /* one of three values below */
  512. #define TIC_COMPUTED 1        /* default; gnuplot figures them */
  513. #define TIC_SERIES 2        /* user-defined series */
  514. #define TIC_USER 3            /* user-defined points */
  515. #define TIC_MONTH 4        /* print out month names ((mo-1)%12)+1 */
  516. #define TIC_DAY 5        /* print out day of week */
  517.     union {
  518.        struct {            /* for TIC_SERIES */
  519.           double start, incr;
  520.           double end;        /* ymax, if VERYLARGE */
  521.        } series;
  522.        struct ticmark *user;    /* for TIC_USER */
  523.     } def;
  524. };
  525.  
  526. /* Defines one ticmark for TIC_USER style.
  527.  * If label==NULL, the value is printed with the usual format string.
  528.  * else, it is used as the format string (note that it may be a constant
  529.  * string, like "high" or "low").
  530.  */
  531. struct ticmark {
  532.     double position;        /* where on axis is this */
  533.     char *label;            /* optional (format) string label */
  534.     struct ticmark *next;    /* linked list */
  535. };
  536.  
  537. /*
  538.  * SS$_NORMAL is "normal completion", STS$M_INHIB_MSG supresses
  539.  
  540.  * printing a status message.
  541.  * SS$_ABORT is the general abort status code.
  542.  from:    Martin Minow
  543.     decvax!minow
  544.  */
  545. #ifdef    vms
  546. #include        <ssdef.h>
  547. #include        <stsdef.h>
  548. #define    IO_SUCCESS    (SS$_NORMAL | STS$M_INHIB_MSG)
  549. #define    IO_ERROR    SS$_ABORT
  550. #endif /* vms */
  551.  
  552.  
  553. #ifndef    IO_SUCCESS    /* DECUS or VMS C will have defined these already */
  554. #define    IO_SUCCESS    0
  555. #endif
  556. #ifndef    IO_ERROR
  557. #define    IO_ERROR    1
  558. #endif
  559.  
  560. /* Some key global variables */
  561. extern TBOOLEAN screen_ok;
  562. extern TBOOLEAN term_init;
  563. extern TBOOLEAN undefined;
  564. extern struct termentry term_tbl[];
  565.  
  566. extern char *alloc();
  567. extern char GPFAR *gpfaralloc();    /* far versions */
  568. extern char GPFAR *gpfarrealloc();
  569. extern void gpfarfree();
  570. /* allocating and managing curve_points structures */
  571. extern struct curve_points *cp_alloc();
  572. extern int cp_extend();
  573. extern int cp_free();
  574. /* allocating and managing surface_points structures */
  575. extern struct surface_points *sp_alloc();
  576. extern int sp_replace();
  577. extern int sp_free();
  578. /* allocating and managing is_curve structures */
  579. extern struct iso_curve *iso_alloc();
  580. extern int iso_extend();
  581. extern int iso_free();
  582.  
  583. /* Windows needs to redefine stdin/stdout functions */
  584. #ifdef _Windows
  585. #include "win/wtext.h"
  586. #endif
  587.